package proxypattern.test;

import proxypattern.base.IPersonBean;
import proxypattern.entity.PersonBean;
import proxypattern.entity.PersonProxy;


import java.util.ArrayList;

/**
 * 动态代理测试类
 * @author yaojianfeng
 */
public class MatchMarkingTestDrive {
    /**
     * 模拟数据库存储
     */
    private ArrayList<IPersonBean> list;

    public static void main(String[] args) {
        MatchMarkingTestDrive matchMarkingTestDrive = new MatchMarkingTestDrive();
        matchMarkingTestDrive.drive();
    }

    private MatchMarkingTestDrive(){
        //初始化一个集合 模拟数据库存放人员信息
        ArrayList<IPersonBean> iPersonBeans = new ArrayList<>();
        IPersonBean owner = new PersonBean();
        owner.setGender("男");
        owner.setInterests("篮球,足球");
        owner.setName("小赵");
        IPersonBean nonOwner = new PersonBean();
        nonOwner.setGender("女");
        nonOwner.setInterests("帅哥,土豪");
        nonOwner.setName("小三");
        IPersonBean ownerProxy = new PersonProxy().getOwnerProxy(owner);
        IPersonBean nowOwnerProxy = new PersonProxy().getNonOwnerProxy(nonOwner);
        iPersonBeans.add(owner);
        iPersonBeans.add(nonOwner);
        iPersonBeans.add(ownerProxy);
        iPersonBeans.add(nowOwnerProxy);
        this.list = iPersonBeans;
    }

    private void drive(){
        IPersonBean ownerProxy = list.get(2);
        System.out.println("姓名: "+ownerProxy.getName());
        try {
            ownerProxy.setHotOrNotRating(10);
        } catch (Exception e) {
            System.out.println("当前用户无法设置本人评分");
            e.printStackTrace();
        }
        IPersonBean nonOwnerProxy = list.get(3);
        nonOwnerProxy.setHotOrNotRating(6);
        System.out.println("评分:"+nonOwnerProxy.getHotOrNotRating());

    }

}
